﻿Imports System.Timers

Public Class Form1
    Private WithEvents Timer1 As New System.Timers.Timer
    Private g_szInitFileName As String    'ini文件
    Public Sub connectDB()
        'イニシャルファイル情報取得

        g_Server.szDrive = GetIniFile("SERVER", "DRIVE", "PostgreSQL ANSI", g_szInitFileName)
        g_Server.szIPadr = GetIniFile("SERVER", "IP", "", g_szInitFileName)
        g_Server.szDbn = GetIniFile("SERVER", "DBN", "ZHENANSF", g_szInitFileName)
        g_Server.szUid = GetIniFile("SERVER", "UID", "sa", g_szInitFileName)
        g_Server.szPas = GetIniFile("SERVER", "PAS", "sa", g_szInitFileName)
        g_Server.iOver = CInt(GetIniFile("SERVER", "OVER", "-1", g_szInitFileName))

        '得到当前用户名
        g_LoginUser = GetIniFile("LOGIN", "user", "admin", g_szInitFileName)

        If False = g_fDBconnect And 0 = g_iDBconnResult Then
            If "" = g_Server.szIPadr Or "0.0.0.0" = g_Server.szIPadr Then
            Else
                g_fDBconnect = True

                'データベース接続
                With g_Server
                    g_iDBconnResult = DBacs.Connect(.szDrive, .szIPadr, .szDbn, .szUid, .szPas, .iOver)
                    If 1 <> g_iDBconnResult Then
                        .szDrive = CStr(IIf("PostgreSQL" = .szDrive, "PostgreSQL ANSI", "PostgreSQL"))
                        g_iDBconnResult = DBacs.Connect(.szDrive, .szIPadr, .szDbn, .szUid, .szPas, .iOver)
                    End If
                End With
            End If
        End If

        setAllErrMsg()
    End Sub

    Delegate Sub setPnlVisibleDele(_flg As Boolean, _equals As Integer)
    Dim setPnlVisibleCall As New setPnlVisibleDele(AddressOf setPnlVisible)
    Private Sub setPnlVisible(_flg As Boolean, _equals As Integer)
        pnlFLB.Visible = _flg

        If _flg = True Then
            If _equals = 0 Then '不同：启用GJB
                pnlGJB.Visible = _flg
                pnlGJB6.Visible = Not _flg
            ElseIf _equals = 1 Then '相同：启用GJB6
                pnlGJB6.Visible = _flg
                pnlGJB.Visible = Not _flg
            End If
        Else
            pnlGJB6.Visible = _flg
            pnlGJB.Visible = _flg
        End If

        pnlNull.Visible = Not _flg
    End Sub
    Delegate Sub setPnlvalueDele(_SPEC As String)
    Dim SetFLBPnlvalueCall As New setPnlvalueDele(AddressOf SetFLBPnlvalue)
    Dim SetGJB6PnlvalueCall As New setPnlvalueDele(AddressOf SetGJB6Pnlvalue)
    Dim SetGJBPnlvalueCall As New setPnlvalueDele(AddressOf SetGJBPnlvalue)

    Public Sub New()

        ' 此调用是设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。
        Me.g_szInitFileName = My.Application.Info.DirectoryPath & "\setting.ini"
        connectDB()
        Timer1.Interval = 1000
        Timer1.Start()


    End Sub

    Private Sub SetFLBPnlvalue(_SPEC As String)
        lblFLB_Type.Text = _SPEC.Split("-")(0)
        lblFLB_str.Text = _SPEC.Split("-")(1)
        lblFLB_num.Text = getSysParam("FLB_need_Count_For_YZZ")
        If lblFLB_Type.Text.Contains("500") Or lblFLB_Type.Text.Contains("600") Then lblFLB_size.Text = "小"
        If lblFLB_Type.Text.Contains("700") Or lblFLB_Type.Text.Contains("800") Then lblFLB_size.Text = "中"
        If lblFLB_Type.Text.Contains("900") Or lblFLB_Type.Text.Contains("1000") Then lblFLB_size.Text = "大"
    End Sub
    Private Sub SetGJB6Pnlvalue(_SPEC As String)
        lblGJB6_type.Text = _SPEC.Split("-")(0)
        lblGJB6_str.Text = _SPEC.Split("-")(1)
        lblGJB6_num.Text = getSysParam("GJB_need_Count_For_YZZ")
        If lblGJB6_type.Text.Contains("500") Or lblGJB6_type.Text.Contains("600") Then lblGJB6_size.Text = "小"
        If lblGJB6_type.Text.Contains("700") Or lblGJB6_type.Text.Contains("800") Then lblGJB6_size.Text = "中"
        If lblGJB6_type.Text.Contains("900") Or lblGJB6_type.Text.Contains("1000") Then lblGJB6_size.Text = "大"
    End Sub
    Private Sub SetGJBPnlvalue(_SPEC As String)
        lblGJB_type.Text = _SPEC.Split("-")(0)
        lblGJB_str.Text = _SPEC.Split("-")(1)
        lblGJB_num.Text = getSysParam("GJB_need_Count_For_YZZ")
        If lblGJB_type.Text.Contains("500") Or lblGJB_type.Text.Contains("600") Then lblGJB_size.Text = "小"
        If lblGJB_type.Text.Contains("700") Or lblGJB_type.Text.Contains("800") Then lblGJB_size.Text = "中"
        If lblGJB_type.Text.Contains("900") Or lblGJB_type.Text.Contains("1000") Then lblGJB_size.Text = "大"
    End Sub

    Private Sub Timer1_Elapsed(sender As Object, e As ElapsedEventArgs) Handles Timer1.Elapsed
        Dim objDB As New clsDB
        '得到RGV是否启用自动控制
        Dim RGV_OPEN_FLG As String = getSysParam("RGV_AUTO_OPEN")
        Dim intEquals_GJB2_YZZ As Integer = objDB.Equals_GJB2_YZZ()

        If RGV_OPEN_FLG = "0" Then '关
            Me.Invoke(setPnlVisibleCall, False, intEquals_GJB2_YZZ)
            Exit Sub
        Else
            Me.Invoke(setPnlVisibleCall, True, intEquals_GJB2_YZZ)
        End If

        '得到预装芯座信息
        Dim dtYZZ As DataTable = objDB.getCurrentData(g_cj_yzz, g_ws_xj_yzz)
        If IsNothing(dtYZZ) = False AndAlso dtYZZ.Rows.Count > 0 Then

            Dim dtSPEC As DataTable = objDB.getProdSpec(dtYZZ(0)("support_model"))

            Dim dtFLB As DataTable = objDB.getFLBSpecInfo(dtSPEC(0)("flb_material_code"))
            Dim dtGJB As DataTable = objDB.getGJBSpecInfo(dtSPEC(0)("gjb_material_code"))

            'FLB信息设定---------------------
            If dtFLB.Rows.Count > 0 Then
                Me.Invoke(SetFLBPnlvalueCall, dtFLB(0)("mst_value").ToString)
            End If
            'FLB信息设定---------------------

            If intEquals_GJB2_YZZ = 0 Then '不同：启用GJB
                Me.Invoke(SetGJBPnlvalueCall, dtFLB(0)("mst_value").ToString)
            ElseIf intEquals_GJB2_YZZ = 1 Then '相同：启用GJB6
                Me.Invoke(SetGJB6PnlvalueCall, dtFLB(0)("mst_value").ToString)
            End If

        End If

    End Sub

    Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click
        Me.Close()
    End Sub

End Class
